package com.caisejingyu.whales.common;

import android.support.annotation.NonNull;

import com.caisejingyu.whales.common.base.IDeviceConfig;
import com.caisejingyu.whales.common.base.impl.DeviceConfig;


/**
 * 说明：
 * 一束光线：1050189980 2018/8/14
 */
@SuppressWarnings({"WeakerAccess", "unused"})
public class AppConfig {
    
    private Builder mBuilder;
    private static AppConfig sInstance;
    
    private AppConfig(Builder builder) {
        if (builder != null) {
            this.mBuilder = builder;
        } else {
            this.mBuilder = new AppConfig.Builder();
        }
    }
    
    public static AppConfig getInstance() {
        if (sInstance == null) {
            synchronized (AppConfig.class) {
                if (sInstance == null) {
                    sInstance = new AppConfig(new AppConfig.Builder());
                }
            }
        }
        return sInstance;
    }
    
    /**
     * 初始化配置
     */
    public static void initialize(AppConfig appConfig) {
        if (appConfig != null) {
            sInstance = appConfig;
        }
    }
    
    public boolean isDebugMode() {
        return mBuilder.mIsDebugMode;
    }
    
    public boolean isLogEnabled() {
        return mBuilder.mIsLogEnabled;
    }
    
    public String getAppName() {
        return mBuilder.mAppName;
    }
    
    public String getAppType() {
        return mBuilder.mAppType;
    }
    
    public String getAppVersion() {
        return mBuilder.mAppVersion;
    }
    
    public IDeviceConfig getDeviceConfig() {
        return mBuilder.mDeviceConfig;
    }
    
    
    
    public String getModel() {
        return mBuilder.model;
    }
    
    public String getSystemName() {
        return  mBuilder.systemName;
    }
    
    public String getSystemVersion() {
        return  mBuilder.systemVersion;
    }
    
    public String getMobileId() {
        return  mBuilder.mobileId;
    }
    
    public String getMobileName() {
        return  mBuilder.mobileName;
    }
    
    public static class Builder {
        /**
         * debug模式
         */
        private boolean mIsDebugMode;
        /**
         * 是否打印日志
         */
        private boolean mIsLogEnabled;
        private String mAppName;
        private String mAppType;
        private String mAppVersion;
        private IDeviceConfig mDeviceConfig = new DeviceConfig();
        
        //新增字段
        private String model;
        private String systemName;
        private String systemVersion;
        private String mobileId;
        private String mobileName;
    
    
        public Builder() {
            this.mIsDebugMode = false;
            this.mIsLogEnabled = false;
            this.mAppName = null;
            this.mAppType = null;
            this.mAppVersion = null;
        }
        
        public Builder isDebugMode(boolean isDebugMode) {
            this.mIsDebugMode = isDebugMode;
            return this;
        }
        
        public Builder isLogEnabled(boolean isLogEnabled) {
            this.mIsLogEnabled = isLogEnabled;
            return this;
        }
        
        public Builder appName(String appName) {
            mAppName = appName;
            return this;
        }
        
        public Builder appType(String appType) {
            mAppType = appType;
            return this;
        }
        
        public Builder appVersion(String appVersion) {
            mAppVersion = appVersion;
            return this;
        }
        
        public Builder deviceConfig(@NonNull IDeviceConfig deviceConfig) {
            mDeviceConfig = deviceConfig;
            return this;
        }
        
        public AppConfig build() {
            return new AppConfig(this);
        }
        
        
        public Builder setmIsDebugMode(boolean mIsDebugMode) {
            this.mIsDebugMode = mIsDebugMode;
            return this;
        }
        
        public Builder setModel(String model) {
            this.model = model;
            return this;
        }
        
        public Builder setSystemName(String systemName) {
            this.systemName = systemName;
            return this;
        }
        
        public Builder setSystemVersion(String systemVersion) {
            this.systemVersion = systemVersion;
            return this;
        }
        
        public Builder setMobileId(String mobileId) {
            this.mobileId = mobileId;
            return this;
        }
        
        public Builder setMobileName(String mobileName) {
            this.mobileName = mobileName;
            return this;
        }
    }
    
    
}
